home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John Noland)
- Newsgroups: comp.lang.c
- Subject: Re: HELP!! with file read/write
- Date: 22 Mar 1996 01:53:59 GMT
- Organization: Prose Software
- Message-ID: <4it17n$jkf@newshost.cyberramp.net>
- References: <4iijmh$brs@cloner2.ix.netcom.com>
- NNTP-Posting-Host: ramp1-6.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <4iijmh$brs@cloner2.ix.netcom.com>, scoshe@ix.netcom.co says...
-
- I'll forgive you the C++ style comments, I'm certain you'll hear about them.
-
- There are several problems: I assume you left out your header files from
- this example for brevity? The declaration of struct _items? The declaration
- and/or definition of itemsize?
- These problems aside,
- If you open a file for update(read/write), when you switch between reading and
- writing, there must be an intervening fflush, fsetpos, fseek or rewind
- operation. You lack this after your write.
-
-
- >void daily_maintainence()
- >{
- > FILE *itemfile;
- > long filepos;
- > struct _items item;
- > itemfile=fopen("items.dat","r+b"); //open for read and write
- > while (fread(&item,itemsize,1,itemfile)==1)
- > {
- > filepos=ftell(itemfile); //for debug
- > item.today=0; //set to zero
- > item.daysleft--; //decrement
- > fseek(itemfile,-itemsize,SEEK_CUR); //seek to where this rec
- >starts
- > filepos=ftell(itemfile); //for debug
- > fwrite(&item,itemsize,1,itemfile); //write it out
- > filepos=ftell(itemfile); //for debug
- > }
- >}
-
-